<template>
  <!-- 歌单模块 -->
  <div class="category"
       v-if="tags.length!==0">
    <div class="tags">
      <span>标签</span>
      <div class="tag-item"
           v-for="(item,index) in tags"
           :key="index"
           @click="tagClick(index)"
           :class="{tagCur:currentIndex==index}">
        {{item.name}}
      </div>
    </div>
    <scroll ref="scroll"
            class="category-scroll"
            :pull-up-load='true'
            @pullingUp='pullingUp'>
      <music-list :personList='musicList'
                  @imgLoad='imgLoad' />
    </scroll>
  </div>
</template>

<script>
import MusicList from 'components/content/musiclist/MusicList'
import Scroll from 'components/common/scroll/Scroll.vue'
import { debounce } from 'assets/common/tool'
import { _getMusicListHot, _getHighquality } from 'network/discover'
import { ImgMixin } from 'mixin/ImgMixin'
export default {
  components: { Scroll, MusicList },
  name: 'MusicListCategory',
  data () {
    return {
      tags: [],
      currentIndex: 0,
      limit: 24,
      page: 1,
      musicList: []

    }
  },
  mixins: [ImgMixin],
  created () {
    _getMusicListHot().then(res => {
      this.tags = res.data.tags
      this.getHighquality()
    })
  },
  methods: {
    // 点击切换
    tagClick (index) {
      this.currentIndex = index
      this.getHighquality()
    },
    getHighquality () {
      _getHighquality(this.tags[this.currentIndex].name, this.limit * this.page).then(res => {
        this.musicList = res.data.playlists
        this.page++
        this.$refs.scroll.finishPullUp()
      })
    },
    pullingUp () {
      debounce(this.getHighquality(), 1000)
    }
  }
}
</script>

<style scoped>
.category {
  width: 100%;
  height: 100%;
}
.category .tags {
  height: 30px;
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
.tags .tag-item {
  padding: 0 10px;
  color: #000;
  cursor: pointer;
}
.category-scroll {
  height: calc(100% - 30px);
  overflow: hidden;
  margin-top: 10px;
}
.tagCur {
  color: #00aa85 !important;
}
</style>
